from fastapi import FastAPI
from backend.app.database import engine
from backend.app.models import Base
from backend.app.routes import votes, websockets
from fastapi.middleware.cors import CORSMiddleware

Base.metadata.create_all(bind=engine)

app = FastAPI()
# 添加 CORS 中间件
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 允许所有来源
    allow_credentials=True,
    allow_methods=["*"],  # 允许所有方法
    allow_headers=["*"],
)
app.include_router(votes.router, prefix="/api/v1")
app.include_router(websockets.router)
